/* 日期时间格式化 */
const formatTime = date => {
	const year = date.getFullYear()
	const month = date.getMonth() + 1
	const day = date.getDate()
	const hour = date.getHours()
	const minute = date.getMinutes()
	const second = date.getSeconds()

	return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => { //只有一位补零
	n = n.toString()
	return n[1] ? n : '0' + n
}

/* 电话号验证 */
const checkPhone = phone => { 
	var patrn = /^((?:13|15|18|14|17)\d{9}|0(?:10|2\d|[3-9]\d{2})[1-9]\d{6,7})$/;
	return patrn.test(phone)
}

module.exports = {
	formatTime,
	checkPhone
}
